<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<!-- 新 Bootstrap 核心 CSS 文件 -->  
 <link rel="stylesheet" href="css/bootstrap.min.css">
  
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->  
<!-- <script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>  
 -->  
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->  
<!-- <script src="js/bootstrap.min.js"></script>  
 -->
<script type="text/javascript" src="js/jquery-3.0.0.min.js"></script>

 <script type="text/javascript">
$(function(){
	 $.ajax({
			url:"/api/v1/role",
			type:"get",
			data:{},
			success:function(d){
				//alert("ok")
				if(d['status']==500){
					alert(d['data']);
				}
				if(d['status']==200){
					show(d['data']);
				}
			},
			error:function(){},
			dataType:"json"
		});
	 
	 function show(data){
		 $.each(data,function (i,j){
				//每个用户的按钮id必须区分开
				$("#role").append("<tr><td>"+j['sort']+"</td>"+"<td>"+j['name']+"</td>"+"<td>"+j['type']+"</td>"+
						"<td>"+j['des']+"</td>"+
						"<td><button id='update"+i+"' class='btn btn-warning btn-primary' type='button' style='margin-right:5px'>修改</button>"
						+"<button id='authorize"+i+"' class='btn btn-success' type='button' style='margin-right:5px'>授权</button>"
						+"<button id='delete"+i+"' class='btn btn-danger btn-primary' type='button'>删除</button></td></tr>");
				
				if(j['type']==1){$("#delete"+i).attr("disabled","true");}
				
				$("#update"+i).click(function(){
					//alert(j['loginName']);
					window.open ("role_update.html?name="+j['name']+"&&sort="+j['sort']+"&&type="+j['type']+"&&id="+j['id']+"&&code="+j['code']+"&&des="+j['des'],
					"newwindow", "height=400px, width=400, top=200px, left=500px, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no")&nbsp;
				});
				
				$("#delete"+i).click(function(){
					disp_confirm(j['id']);
				});
				
				$("#authorize"+i).click(function(){
					window.open ("role_resource.html?id="+j['id'],
							"newwindow", "height=400px, width=400, top=200px, left=500px, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no")&nbsp;
				});
			});
	 }
	 
	 
	 $("#save").click(function(){
			window.open ("role_save.html", "newwindow", "height=400px, width=600, top=200px, left=500px, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no")&nbsp; 
	 });
	 
	//删除跳出 确认窗口，确定才会继续操作
		function disp_confirm(idd)
		  {
		  var r=confirm("确定要删除用户吗？")
		  if (r==true){
			  //alert(idd);
			  $.ajax({
					url:"/api/v1/role/"+idd,
					type:"DELETE",
					data:{},
					success:function(d){
						if(d['status']==200){
							 alert("删除成功");
							 window.location.href = window.location.href;
						}
						if(d['status']==500){
							alert(d['data']);
						}
					},
					error:function(){},
					dataType:"json"
				});
			
		  }else {}
		  }
});
</script>
</head>
<body>
<div class="container-fluid">
	<div class="row-fluid">
		<div class="span12" style="height: 400px">
			<table class="table">
				<thead>
					<tr>
						<th>
							序号
						</th>
						<th>
							角色名称
						</th>
						<th>
							角色类型
						</th>
						<th>
							角色描述
						</th>
						<th>
							操作
						</th>
					</tr>
				</thead>
				<tbody id="role">
				</tbody>
			</table>
		</div>
		<button id="save" class='btn btn-primary' type='button' style='margin-right:5px'>新增</button>&nbsp;
	</div>
</div>
</body>
</html>